package www.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.admin.dao.IUserDao;
import www.admin.model.User;
import www.admin.mybatis.Criteria;
import www.admin.service.IUserService;
import www.admin.utils.Layui;
import www.admin.utils.MessageConstant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class UserServiceImpl implements IUserService{


	public Layui queryPage (Criteria<User> param){
		PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<User> list = userRepository.queryPage(param);
		PageInfo<User> paInfo = new PageInfo<User>(list);
	    return Layui.data((int)paInfo.getTotal(), paInfo.getList());
	}

	public Integer queryPageCount (Criteria<User> param){
		return (Integer) userRepository.queryPageCount(param);
	}

	public User  queryEntity (String id ){
		return userRepository.queryEntity(id);
	}

	public String deleteById (String id ){
		int result = userRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_19;
			}
			return null;
	}

	public String insert(User record ){
		int result = userRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_12;
			}
			return null;
	}

	public String update (Criteria<User> param){
		int result = userRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_16;
			}
			return null;
	}
	
	@Override
	public List<User> queryPageList(Criteria<User> param) {
		return userRepository.queryPage(param);
	}

	@Resource
	private IUserDao userRepository;

}